package com.xk.Reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class PersonReflectTest {
    public static void main(String[] args) {
        Person peason1=new Person("张三","男",19);

        //通过获取对象的getClass方法
//        Class<?> clazz=peason1.getClass();

        //通过类的Class属性
//        Class<?> clazz1=com.xk.Reflect.Peason.class;

        //通过Class类的静态方法forMane();
        Class<?> clazz2=null;
        try {
            clazz2=Class.forName("com.xk.Reflect.Person");
        } catch (ClassNotFoundException e) {
           e.printStackTrace();
        }

        //获取属性
        System.out.println("====获取属性====");
        Field[] fieldList= null;
        if (clazz2 != null) {
            fieldList = clazz2.getDeclaredFields();
        }
        if (!(fieldList == null)) {
            for (Field f:fieldList){
                System.out.println(f);
            }
        }


        //获取成员方法
        Method[] methods=clazz2.getMethods();
        Method[] methods1= clazz2.getDeclaredMethods();
        System.out.println("methods:");
        for (Method m:methods){
            System.out.println(m);
        }
        System.out.println("metfods1:");
        for (Method m:methods1){
            System.out.println(m);
        }
    }
}
